home *** CD-ROM | disk | FTP | other *** search
- Path: ocbbs.gen.nz!not-for-mail
- From: steve@hn.ocbbs.gen.nz (Steve Detoni)
- Newsgroups: comp.lang.c++
- Subject: Re: Fastest way to index thru an array????
- Date: 16 Jan 1996 12:23:48 +1300
- Message-ID: <4denm4$514@hn.ocbbs.gen.nz>
- References: <4d1g3k$o09@solaris.cc.vt.edu>
- NNTP-Posting-Host: hn.hn.planet.gen.nz
- X-Newsreader: TIN [version 1.2 PL2]
-
- Ashutosh Gokhale (ashutosh) wrote:
- : Suppose I have an array A[][][] which I declare as
- : double ***A and then assign memory to it using new operator.
- : Now consider that A has dimensions A[50][60][70]. Then I can index thru ALL
- : entries of A using
- : for(i=1; i<50; i++)
- : {
- : for(j=1; j<60; j++)
- : {
- : for(k=1; k<70; k++)
- : {
- : A[i][j][k] = <some expression>;
- : }
- : }
- : }
- : But the above way is surely the most time-INEFFICIENT way.
- : Can someone suggest me the MOST time efficient way of indexing through A[][][]?
-
- : Thanks a lot
- Umm not really .... you can treat the whole array as a single dimention
- if you so desire .... so :
- const int Z = 50, Y = 60, X = 70;
- const int MAXITS = Z * (X * Y);
- int A[Z][Y][X];
- int* pA = A;
-
- for (long int count = 0; count < MAXITS; count++)
- pA[count] = 0;
-
- // The above should work if you want to initialise all data items to 0,
- // ore you can use memset(),
- memset (A, sizeof (A), 0); // I think from memory.
-
- // or even
- for (long int count = 0; count < MAXITS; count++)
- A[count] = 0; // No array size checking !!!
-
- etc
- If you are trying to find an item within a array then some sort of sort
- algorithm may be need to be implemented, something like quick sort, heap
- sort that has the corrosponding Numeric value and indexs.
-
- Steve.
-
-